package com.agnes.network.dialog;

import android.annotation.SuppressLint;
import android.app.Dialog;
import android.content.Context;
import android.os.Bundle;
import android.view.*;

import com.agnes.network.R;

/**
 * Desc:   网络加载对话框
 * Creator ling
 * Date:   2017/9/13 0013 15:37
 */

public class ProgressDialog extends Dialog {
    private String msg;

    public ProgressDialog(Context context) {
        this(context, "");
    }

    private ProgressDialog(Context context, String msg) {
        super(context, R.style.NetWork_MyDialog);
        setCancelable(false);
        setCanceledOnTouchOutside(false);
        this.msg = msg;
    }


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        //以view来引入布局
        @SuppressLint("InflateParams")
        View view = LayoutInflater.from(getContext()).inflate(R.layout.network_dialog_loading, null);
        if (view != null) {
            setContentView(view);
            /*TextView tvMsg = view.findViewById(R.id.msg);
            if (TextUtils.isEmpty(msg)) tvMsg.setVisibility(View.GONE);
            else tvMsg.setText(msg);*/
        }

        Window dialogWindow = getWindow();
        if (dialogWindow != null) {
            dialogWindow.setGravity(Gravity.CENTER);
            WindowManager.LayoutParams params = dialogWindow.getAttributes();
            params.width = WindowManager.LayoutParams.WRAP_CONTENT;
            params.height = WindowManager.LayoutParams.WRAP_CONTENT;
            dialogWindow.setAttributes(params);
        }
    }


}
